use serde_json::Value;
use tauri::command;
use crate::types::ApiResponse;

#[command]
pub fn format_json(input: String) -> ApiResponse {
    match serde_json::from_str::<Value>(&input) {
        Ok(json) => {
            match serde_json::to_string_pretty(&json) {
                Ok(formatted) => ApiResponse::success(formatted),
                Err(e) => ApiResponse::error(format!("格式化失败: {}", e))
            }
        },
        Err(e) => ApiResponse::error(format!("无效的 JSON: {}", e))
    }
} 